package com.freak.wanandroid.model.search;

import com.freak.httpmanager.callback.SubscriberCallBack;
import com.freak.wanandroid.base.repository.BaseRepository;
import com.freak.wanandroid.bean.HistoryData;
import com.freak.wanandroid.bean.TopSearchData;
import com.freak.wanandroid.model.search.db.RealmHelper;
import com.freak.wanandroid.net.HttpResultFunc;

import java.util.List;

import io.reactivex.rxjava3.core.Observable;


/**
 * Created by 74099 on 2018/9/5.
 */

public class SearchRepository extends BaseRepository {
    private RealmHelper mRealmHelper = new RealmHelper();

    public List<HistoryData> loadAllHistoryData() {
        return mRealmHelper.selectAllHistory();
    }

    public void addHistoryData(String data) {
        mRealmHelper.saveHistory(data);
    }

    public void clearHistoryData() {
        mRealmHelper.clearHistory();
    }

    public void getTopSearchData(SubscriberCallBack<List<TopSearchData>> observer) {
        Observable observable = mApiService.doSearchHot().map(new HttpResultFunc<List<TopSearchData>>());
        addSubscription(observable, observer);
    }
}
